package com.smartens.boit.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.smartens.boit.R;
import com.smartens.boit.base.BaseActivity;

/**
 * @Description 设备类型单选
 * @Author songtt
 * @Date 2021/3/4
 */

public class SingleTypeActivity extends BaseActivity {
    private LinearLayout lin1;
    private LinearLayout lin2;
    private LinearLayout lin3;
    private LinearLayout lin4;
    private CheckBox rb1;
    private CheckBox rb2;
    private CheckBox rb3;
    private CheckBox rb4;
    private TextView cancel;
    private TextView save;
    private String typeText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_type);

        initView1();
        getData();
        click();
    }

    @Override
    protected void initView() {

    }

    public void initView1(){
        lin1 = findViewById(R.id.lin_01);
        lin2 = findViewById(R.id.lin_02);
        lin3 = findViewById(R.id.lin_03);
        lin4 = findViewById(R.id.lin_04);
        rb1 = findViewById(R.id.rb_01);
        rb2 = findViewById(R.id.rb_02);
        rb3 = findViewById(R.id.rb_03);
        rb4 = findViewById(R.id.rb_04);
        cancel = findViewById(R.id.cancel);
        save = findViewById(R.id.save);
    }

    @Override
    protected void initData() {

    }

    public void getData(){
        Intent intent =getIntent();
        Bundle bundle= intent.getExtras();
        String type = bundle.getString("type");

        if(type != null){
            if("单相单控".equals(type)){
                rb1.setChecked(true);
                typeText = "单相单控";
            }else if("单相三控".equals(type)){
                rb2.setChecked(true);
                typeText = "单相三控";
            }else if("三相单控".equals(type)){
                rb3.setChecked(true);
                typeText = "三相单控";
            }else if("三相三控".equals(type)){
                rb4.setChecked(true);
                typeText = "三相三控";
            }
        }

    }

    public void click(){
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SingleTypeActivity.this.finish();
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SingleTypeActivity.this,EquipmentInfoActivity.class);

                intent.putExtra("backType",typeText);
                setResult(1001, intent);
                //    结束当前这个Activity对象的生命
                finish();
            }
        });

        rb1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(rb1.isChecked()){
                    rb2.setChecked(false);
                    rb3.setChecked(false);
                    rb4.setChecked(false);
                    typeText = "单相单控";
                }
            }
        });
        rb2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(rb2.isChecked()){
                    rb1.setChecked(false);
                    rb3.setChecked(false);
                    rb4.setChecked(false);
                    typeText = "单相三控";
                }
            }
        });
        rb3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(rb3.isChecked()){
                    rb2.setChecked(false);
                    rb1.setChecked(false);
                    rb4.setChecked(false);
                    typeText = "三相单控";
                }
            }
        });
        rb4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(rb4.isChecked()){
                    rb2.setChecked(false);
                    rb3.setChecked(false);
                    rb1.setChecked(false);
                    typeText = "三相三控";
                }
            }
        });
    }


}